package com.yunxin.customui.service.createimpl;

import com.yunxin.customui.bean.table.TableBean;
import com.yunxin.customui.bean.table.methodresult.ListDataBeansResult;
import com.yunxin.customui.bean.table.datatable.TableBusinessConfig;
import com.yunxin.customui.service.CustomPageTemplate;
import com.yunxin.tools.commonbean.DataBean;
import com.yunxin.tools.commonbean.tips.TipsMessage;
import com.yunxin.customui.bean.table.CustomFormValueBean;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class CustomTableImpl extends CustomPageTemplate<Map<String, ListDataBeansResult>, TableBusinessConfig, TableBean,CustomFormValueBean> {




    /**
     * 获取数据 基于businessid  ,这个项目用不到
     *
     * @param config              配置
     * @param customFormValueBean 自定义表单bean价值
     */
    @Override
    protected Map<String, ListDataBeansResult> getData(TableBusinessConfig config, CustomFormValueBean customFormValueBean){
//        //根据条件获取数据的id集合
//        List<String> ids = new ArrayList<>(idUtil.getIds(tableId, customFormValueBean.getPlantId(), customFormValueBean.getGenId(),
//                customFormValueBean.getBusKVId(), customFormValueBean.getAgcId()));
//        //获取数据
//        Map<String, ListDataBeansResult> dataMap = customPageDataService.getDataList(ids, customFormValueBean.getBeginTime(), customFormValueBean.getEndTime());
//        //处理结果
//        if (handler != null){
//            dataMap = handler.apply(dataMap);
//        }
//        return dataMap;
        return null;
    }

    /**
     * 构建
     *
     * @param resultMap 数据
     * @param config    配置
     */
    @Override
    protected TableBean build(Map<String, ListDataBeansResult> resultMap, TableBusinessConfig config) {
        TableBean tableBean = new TableBean(config);
        List<TipsMessage> tipsMessageList = new ArrayList<>();
        Map<String,List<DataBean>> dataMap = new HashMap<>();
        for (Map.Entry<String, ListDataBeansResult> entry : resultMap.entrySet()) {
            String dataId = entry.getKey();
            ListDataBeansResult value = entry.getValue();
            dataMap.put(dataId,value.getDataBeans());
            tipsMessageList.addAll(value.getMessageList());
        }
        tableBean.build(dataMap);
        tableBean.setTipsMessageList(tipsMessageList);
        return tableBean;
    }

}
